import tkinter as tk
from tkinter import ttk
from .tooltip import ToolTip

class ParameterSettingsPanel(ttk.LabelFrame):
    """规则设置面板"""
    
    def __init__(self, parent):
        super().__init__(parent, text="规则设置")
        self.create_widgets()
        
    def create_widgets(self):
        """创建参数输入组件"""
        # 创建样式
        self.style = ttk.Style()
        self.style.configure('Disabled.TSpinbox', 
                           foreground='#999999',
                           background='#F0F0F0')
        
        # 时间限制
        time_frame = ttk.Frame(self)
        time_frame.pack(fill=tk.X, pady=5)
        
        ttk.Label(time_frame, text="时间限制（分钟）:").grid(row=0, column=0, padx=5, sticky=tk.W)
        self.time_limit = ttk.Spinbox(time_frame, from_=1, to=300, style='TSpinbox')
        self.time_limit.grid(row=0, column=1, sticky=tk.W)
        
        # 有效时间
        ttk.Label(time_frame, text="有效时间（分钟）:").grid(row=1, column=0, padx=5, sticky=tk.W)
        self.valid_time = ttk.Spinbox(time_frame, from_=1, to=300, style='TSpinbox')
        self.valid_time.grid(row=1, column=1, sticky=tk.W)
        
        # 惩罚间隔时间
        ttk.Label(time_frame, text="惩罚间隔（分钟）:").grid(row=2, column=0, padx=5, sticky=tk.W)
        self.penalty_interval = ttk.Spinbox(time_frame, from_=0, to=100, increment=0.1, style='TSpinbox')
        self.penalty_interval.grid(row=2, column=1, sticky=tk.W)
        
        # 每次惩罚分数
        ttk.Label(time_frame, text="每次惩罚分数:").grid(row=3, column=0, padx=5, sticky=tk.W)
        self.penalty_points = ttk.Spinbox(time_frame, from_=0, to=100, style='TSpinbox')
        self.penalty_points.grid(row=3, column=1, sticky=tk.W)
        
    def get_values(self):
        """获取所有参数值"""
        return {
            'time_limit': self.time_limit.get(),
            'valid_time': self.valid_time.get(),
            'penalty_interval': self.penalty_interval.get(),
            'penalty_points': self.penalty_points.get()
        }
        
    def set_inputs_state(self, state):
        """设置输入框状态"""
        style = 'Disabled.TSpinbox' if state == 'disabled' else 'TSpinbox'
        self.time_limit.config(state=state, style=style)
        self.valid_time.config(state=state, style=style)
        self.penalty_interval.config(state=state, style=style)
        self.penalty_points.config(state=state, style=style)
